package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.SysAlertConfig;
import com.ruoyi.system.mapper.SysAlertConfigMapper;
import com.ruoyi.system.service.ISysAlertConfigService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 预警项目配置 服务层实现
 *
 * @author ruoyi
 */
@Service
public class SysAlertConfigServiceImpl implements ISysAlertConfigService {
    private final SysAlertConfigMapper sysAlertConfigMapper;

    public SysAlertConfigServiceImpl(SysAlertConfigMapper sysAlertConfigMapper) {
        this.sysAlertConfigMapper = sysAlertConfigMapper;
    }

    /**
     * 查询预警项目配置信息
     *
     * @param id 预警项目配置ID
     * @return 预警项目配置信息
     */
    @Override
    public SysAlertConfig selectSysAlertConfigById(Long id) {
        return sysAlertConfigMapper.selectSysAlertConfigById(id);
    }

    /**
     * 根据预警大项类别和预警级别查询配置
     *
     * @param projectCate 预警大项类别
     * @param alertLevel  预警级别
     * @return 预警项目配置列表
     */
    @Override
    public List<SysAlertConfig> selectSysAlertConfigByProjectAndLevel(String projectCate, String alertLevel) {
        return sysAlertConfigMapper.selectSysAlertConfigByProjectAndLevel(projectCate, alertLevel);
    }

    /**
     * 查询预警项目配置列表
     *
     * @param sysAlertConfig 预警项目配置信息
     * @return 预警项目配置集合
     */
    @Override
    public List<SysAlertConfig> selectSysAlertConfigList(SysAlertConfig sysAlertConfig) {
        return sysAlertConfigMapper.selectSysAlertConfigList(sysAlertConfig);
    }

    /**
     * 新增预警项目配置
     *
     * @param sysAlertConfig 预警项目配置信息
     * @return 结果
     */
    @Override
    public int insertSysAlertConfig(SysAlertConfig sysAlertConfig) {
        return sysAlertConfigMapper.insertSysAlertConfig(sysAlertConfig);
    }

    /**
     * 修改预警项目配置
     *
     * @param sysAlertConfig 预警项目配置信息
     * @return 结果
     */
    @Override
    public int updateSysAlertConfig(SysAlertConfig sysAlertConfig) {
        return sysAlertConfigMapper.updateSysAlertConfig(sysAlertConfig);
    }

    /**
     * 批量删除预警项目配置
     *
     * @param ids 需要删除的预警项目配置ID
     * @return 结果
     */
    @Override
    public int deleteSysAlertConfigByIds(Long[] ids) {
        return sysAlertConfigMapper.deleteSysAlertConfigByIds(ids);
    }

    /**
     * 删除预警项目配置信息
     *
     * @param id 预警项目配置ID
     * @return 结果
     */
    @Override
    public int deleteSysAlertConfigById(Long id) {
        return sysAlertConfigMapper.deleteSysAlertConfigById(id);
    }

    /**
     * 校验预警项目配置是否唯一
     *
     * @param sysAlertConfig 预警项目配置信息
     * @return 结果
     */
    @Override
    public boolean checkAlertConfigUnique(SysAlertConfig sysAlertConfig) {
        SysAlertConfig info = sysAlertConfigMapper.checkAlertConfigUnique(
                sysAlertConfig.getProjectCate(),
                sysAlertConfig.getAlertLevel(),
                sysAlertConfig.getItemCate());
        return info != null && (sysAlertConfig.getId() == null || !info.getId().equals(sysAlertConfig.getId()));
    }
}